package com.ksyun.seckill;

import com.ksyun.common.util.base.RuntimeUtil;
import com.ksyun.seckill.bo.EnvInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

/**
 * 
 */
@Slf4j
@Configuration
public class StartEventListener {

    @Autowired
    private EnvInfo envInfo;

    @Async
    @Order
    @EventListener(WebServerInitializedEvent.class)
    public void afterStart(WebServerInitializedEvent event) {
        String appName = envInfo.getName();
        String appVer = envInfo.getVer();
        String env = envInfo.getEnvStr();
        int port = event.getWebServer().getPort();

        Integer pid = RuntimeUtil.getPid();


        log.info("{}启动完成，ver:{},env:{},pid:{},port:{}", appName, appVer, env,pid, port);
    }

}